package com.yonyou.sto.modules.ims.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonyou.sto.domain.InvoiceStatusEnums;
import com.yonyou.sto.modules.ims.model.ImsCancleInvoice;
import com.yonyou.sto.modules.ims.model.ImsCancleInvoiceItem;
import com.yonyou.sto.modules.ims.model.ImsInvoiceItem;
import com.yonyou.sto.modules.ims.model.ImsReturnInvoiceItem;
import com.yonyou.sto.modules.ims.service.ImsCancleInvoiceItemService;
import com.yonyou.sto.modules.ims.mapper.ImsCancleInvoiceItemMapper;
import com.yonyou.sto.modules.ims.service.ImsInvoiceItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
*
*/
@Service
public class ImsCancleInvoiceItemServiceImpl extends ServiceImpl<ImsCancleInvoiceItemMapper, ImsCancleInvoiceItem>
implements ImsCancleInvoiceItemService{

    @Resource
    private ImsInvoiceItemService itemService;

    @Override
    public boolean add(String iid, String rid) {
        List<ImsInvoiceItem> items = itemService.listByBillIds(Collections.singletonList(iid));
        items.forEach(item->{
            ImsCancleInvoiceItem re = new ImsCancleInvoiceItem();
            BeanUtil.copyProperties(item, re);
            re.setId(null);
            re.setBillId(rid);
            re.setStatus(InvoiceStatusEnums.CANCEL.getCode());
            baseMapper.insert(re);
        });
        return true;
    }

    @Override
    public List<ImsCancleInvoiceItem> listByBillIds(List<String> collect) {
        List<ImsCancleInvoiceItem> items=baseMapper.listByBillIds(collect);
        items.forEach(es->{
            es.getBillId();
        });
        return items;
    }
}
